﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using EmptyWallGallery.Core.Utilities;

namespace EmptyWallGallery.Core.BLL
{
    public class ArticleListView
    {
        public string UniqueId { get; set; }
        public string Price { get; set; }
        public string ArrayCatId { get; set; }
        public string ArticlePath { get; set; }
        public int? PostVisible { get; set; }
        public string Body { get; set; }
        public string ArticlePassword { get; set; }
        public string TitleNone { get; set; }
        public int ArticlesId { get; set; }
        public string Title { get; set; }
        public string Abstract { get; set; }
        public bool Approved { get; set; }
        public int ViewCount { get; set; }
        public int CategoryId { get; set; }
        public DateTime? CreatedDate { get; set; }
        public DateTime ExpireDate { get; set; }
        public DateTime? ReleaseDate { get; set; }
        public string ImagePath { get; set; }
        public string Currency { get; set; }
        public string CodeName { get; set; }
        public int ChildCatId { get; set; }
        public string UserName { get; set; }
        public int? Quantity { get; set; }
        public string SourceUrl { get; set; }
        public string SourceName { get; set; }
    }

    public class Articles
    {
        public static Articles Instance
        {
            get { return new Articles(); }
        }

        private static ArticleListView LoadDataFromListItem(Article item)
        {
            var objArticle = new ArticleListView
                                 {
                                     ArticlesId = item.ArticlesID,
                                     Title = item.Title,
                                     Abstract = item.Abstract,
                                     ReleaseDate = item.ReleaseDate,
                                     ImagePath = item.ImagePath,
                                     TitleNone = item.TitleNone,
                                     ArticlePath = item.ArticlePath,
                                     CreatedDate = item.CreatedDate,
                                     UniqueId = item.UniqueID
                                 };
            return objArticle;
        }

        public ArticleListView Create(string title, bool isPicture, string @abstract, bool? approved,
            bool commentEnabled, DateTime expireDate, DateTime releaseDate, string imagePath, bool isMedia,
            string titleNone, string articlePassword, int? postVisible, string articlePath, int userId,
            DateTime createdDate, bool isTopPage, int siteId, string postBy, string sourceName, string sourceUrl)
        {

            var guildId = Guid.NewGuid().ToString();
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);

            var objArticle = new Article
                                 {
                                     Title = title,
                                     Abstract = @abstract,
                                     CommentsEnabled = commentEnabled,
                                     ExpireDate = expireDate,
                                     ReleaseDate = releaseDate,
                                     ImagePath = imagePath,
                                     TitleNone = titleNone,
                                     ArticlePath = articlePath,
                                     CreatedDate = createdDate,
                                     ViewCount = 0,
                                     ViewCountMonth = 0,
                                     SiteID = siteId,
                                     PostBy = Guid.Parse(postBy),
                                     UniqueID = guildId
                                 };

            dc.Articles.InsertOnSubmit(objArticle);
            dc.SubmitChanges();

            var query = (dc.Articles.Where(p => p.UniqueID == guildId)).SingleOrDefault();

            return LoadDataFromListItem(query);
        }

        public ArticleListView CreateProduct(string title, string @abstract,
    DateTime releaseDate, string imagePath, string titleNone,
    string articlePath, DateTime createdDate , string postBy, int quantity)
        {
            var guildId = Guid.NewGuid().ToString();
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);

            var objArticle = new Article
            {
                Title = title,
                Abstract = @abstract,
                ReleaseDate = releaseDate,
                ImagePath = imagePath,
                TitleNone = titleNone,
                ArticlePath = articlePath,
                CreatedDate = createdDate,
                ExpireDate = createdDate.AddYears(10),
                SiteID = Configs.SiteId,
                ViewCount = 0,
                ViewCountMonth = 0,
                PostBy = Guid.Parse(postBy),
                UniqueID = guildId
            };

            dc.Articles.InsertOnSubmit(objArticle);
            dc.SubmitChanges();

            dynamic query = (dc.Articles.Where(p => p.UniqueID == guildId)).SingleOrDefault();

            return LoadDataFromListItem(query);
        }

        public ArticleListView Update(string title, string @abstract, bool approved,
            bool commentEnabled, string imagePath, int articleId, DateTime releaseDate)
        {

            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var objArticle = (dc.Articles.Where(p => p.ArticlesID == articleId)).Single();
            objArticle.Title = title;
            objArticle.Abstract = @abstract;
            objArticle.CommentsEnabled = commentEnabled;
            objArticle.ImagePath = imagePath;
            objArticle.ReleaseDate = releaseDate;

            dc.SubmitChanges();

            dynamic query = (from p in dc.Articles where p.ArticlesID == articleId select p).SingleOrDefault();

            return LoadDataFromListItem(query);
        }

        public bool UpdateImagePath(string imagePath, int articleId)
        {
            try
            {
                var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
                var objArticle = (dc.Articles.Where(p => p.ArticlesID == articleId)).Single();
                objArticle.ImagePath = imagePath;

                dc.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public List<ArticleListView> GetTopArticle(int item, int siteId, int catId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                var query = from p in dc.Articles
                            join tempArticleCat in dc.TempArticleCats on p.ArticlesID equals tempArticleCat.ArticleID
                            join user in dc.aspnet_Users on p.PostBy equals user.UserId
                            where p.SiteID == siteId && p.ReleaseDate < DateTime.Now &&
                            tempArticleCat.CatID == catId
                            orderby p.ReleaseDate descending
                            select new ArticleListView
                            {
                                ArticlesId = p.ArticlesID,
                                Title = p.Title,
                                Abstract = p.Abstract,
                                CreatedDate = p.CreatedDate,
                                ViewCount = int.Parse(p.ViewCount.ToString()),
                                ArticlePath = p.ArticlePath,
                                ReleaseDate = p.ReleaseDate,
                                ImagePath = p.ImagePath,
                                UserName = user.UserName
                            };

                return query.Take(item).ToList();
            }
        }

        public List<ArticleListView> GetTopArticle(int siteId, int catId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                var query = from p in dc.Articles
                            join tempArticleCat in dc.TempArticleCats on p.ArticlesID equals tempArticleCat.ArticleID
                            join user in dc.aspnet_Users on p.PostBy equals user.UserId
                            where p.SiteID == siteId && p.ReleaseDate < DateTime.Now &&
                            tempArticleCat.CatID == catId 
                            orderby p.CreatedDate descending
                            select new ArticleListView
                            {
                                ArticlesId = p.ArticlesID,
                                Title = p.Title,
                                CreatedDate = p.CreatedDate,
                                ViewCount = int.Parse(p.ViewCount.ToString()),
                                ArticlePath = p.ArticlePath,
                                ReleaseDate = p.ReleaseDate,
                                ImagePath = p.ImagePath,
                                UserName = user.UserName
                            };

                return query.ToList();
            }
        }

        public void Delete(int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_Delete(articleId);
            }
        }

        public void SetTempArticleCat(int t, int catId, int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_SetTempArticleCat(catId, t, articleId);
            }
        }

        public void SetTempArticleTag(int type, int tagId, int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_SetTempArticleTag(type, tagId, articleId);
            }
        }

        public void RemoveTempArticleCat(int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_RemoveTempArticleCat(articleId);
            }
        }

        public void RemoveTempArticleTag(int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_RemoveTempArticleTag(articleId);
            }
        }

        public void UpdateArticlePath(string articlePath, int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_UpdatePath(articlePath, articleId);
            }
        }

        public List<Justin_Article_GetByCatResult> GetByCat(int catId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                return dc.Justin_Article_GetByCat(catId).ToList();
            }
        }

        public List<Justin_Article_GetByTopCatResult> GetByTopCat(int catId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                return dc.Justin_Article_GetByTopCat(catId).ToList();
            }
        }

        public List<Justin_Article_GetAllResult> GetAll(int siteId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                return dc.Justin_Article_GetAll(siteId).ToList();
            }
        }

        public void UpdateViewCount(int articleId)
        {
            using (var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString))
            {
                dc.Justin_Article_UpdateCount(articleId);
            }
        }

        public ArticleListView GetProEdit(int articleId)
        {
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var objArticle = new ArticleListView();

            var query = (from p in dc.Articles where p.ArticlesID == articleId select p).SingleOrDefault();

            if ((query == null))
            {
                return null;
            }

            objArticle.ArticlesId = query.ArticlesID;
            objArticle.CreatedDate = query.CreatedDate;
            objArticle.ImagePath = query.ImagePath;
            objArticle.ReleaseDate = query.ReleaseDate;
            objArticle.Title = query.Title;
            objArticle.TitleNone = query.TitleNone;
            objArticle.ArticlePath = query.ArticlePath;

            var sPath = Configs.ArticleFile + "ListFile\\" + DateTime.Parse(objArticle.CreatedDate.ToString()).Year + "\\" +
                        DateTime.Parse(objArticle.CreatedDate.ToString()).Month + "\\" + DateTime.Parse(objArticle.CreatedDate.ToString()).Day + "\\" +
                        objArticle.ArticlesId + ".xml";

            if (File.Exists(sPath))
            {
                var xmldoc = new XmlDocument();
                xmldoc.Load(sPath);

                var nodelist = xmldoc.SelectNodes("Articles/Article");
                XmlNode nodedetail = null;

                if (nodelist != null)
                {
                    var xmlNode = nodelist.Item(0);
                    if (xmlNode != null) nodedetail = xmlNode.SelectSingleNode("Body");
                }
                if (nodedetail != null) objArticle.Body = nodedetail.InnerText;
            }

            return objArticle;
        }

        public ArticleListView GetByEdit(int articleId)
        {
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var objArticle = new ArticleListView();
            var query = (from p in dc.Articles where p.ArticlesID == articleId select p).SingleOrDefault();

            if ((query != null))
            {
                objArticle.ArticlesId = query.ArticlesID;
                objArticle.Abstract = HttpContext.Current.Server.HtmlDecode(query.Abstract);
                objArticle.CreatedDate = query.CreatedDate;
                objArticle.ImagePath = query.ImagePath;
                objArticle.ReleaseDate = query.ReleaseDate;
                objArticle.Title = query.Title;
                objArticle.TitleNone = query.TitleNone;
                objArticle.ArticlePath = query.ArticlePath;

                var sourceFolder = Configs.ArticleFile + "ListFile\\" +
                   DateTime.Parse(objArticle.CreatedDate.ToString()).Year + "\\" +
                   Common.Instance.Right("0" + DateTime.Parse(objArticle.CreatedDate.ToString()).Month, 2) +
                   "\\" +
                   Common.Instance.Right("0" + DateTime.Parse(objArticle.CreatedDate.ToString()).Day, 2) +
                   "\\";

                var sPath = sourceFolder + objArticle.ArticlesId + ".xml";
                if (File.Exists(sPath))
                {
                    var xmldoc = new XmlDocument();
                    xmldoc.Load(sPath);

                    var nodelist = xmldoc.SelectNodes("Articles/Article");
                    XmlNode nodedetail = null;

                    if (nodelist != null)
                    {
                        var xmlNode = nodelist.Item(0);
                        if (xmlNode != null) nodedetail = xmlNode.SelectSingleNode("Body");
                    }
                    if (nodedetail != null) objArticle.Body = nodedetail.InnerText;
                }

                return objArticle;
            }
            return null;
        }

        public ArticleListView GetById(int articleId)
        {
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var objArticle = new ArticleListView();
            var query = (from p in dc.Articles where p.ArticlesID == articleId select p).SingleOrDefault();

            if ((query != null))
            {
                objArticle.ArticlesId = query.ArticlesID;
                objArticle.Abstract = HttpContext.Current.Server.HtmlDecode(query.Abstract);
                objArticle.ImagePath = query.ImagePath;
                objArticle.ReleaseDate = query.ReleaseDate;
                objArticle.Title = query.Title;
                objArticle.ArticlePath = query.ArticlePath;

                return objArticle;
            }
            return null;
        }

        public string GetAllCat(int t, int articleId)
        {
            var strOut = new StringBuilder();
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var query = dc.Justin_Article_GetAllCat(articleId);

            foreach (var justinArticleGetAllCatResult in query)
            {
                switch (t)
                {
                    case 0:
                        strOut.Append("<a href=\"ArticleUpdate.aspx?action=getByCat&CatID=").Append(justinArticleGetAllCatResult.CatID).Append("\">").Append(justinArticleGetAllCatResult.Title).Append("</a>,");
                        break;
                    case 2:
                        strOut.Append("<a href=\"/c").Append(justinArticleGetAllCatResult.CatID).Append("s").Append(justinArticleGetAllCatResult.SubCat).Append("/").Append(justinArticleGetAllCatResult.TitleNone).Append("\" title=\"").Append(justinArticleGetAllCatResult.Title).Append("\">").Append(justinArticleGetAllCatResult.Title).Append("</a>,");
                        break;
                    case 1:
                        strOut.Append(justinArticleGetAllCatResult.CatID).Append(",");
                        break;
                }
            }
            return strOut.ToString();
        }

        public List<ArticleListView> Search(string keyword, int siteId)
        {
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var query = (from p in dc.Articles
                         where p.Title.Contains(keyword) && p.SiteID == siteId
                         orderby p.ArticlesID descending
                         select new ArticleListView
                         {
                             ArticlePath = p.ArticlePath,
                             ArticlesId = p.ArticlesID,
                             ImagePath = p.ImagePath,
                             Title = p.Title,
                             Abstract = p.Abstract,
                             CreatedDate = p.CreatedDate,
                         }).Take(1000);

            return query.ToList();
        }

        public List<ArticleListView> Search(string keyWord, int catId, Guid userId,
            int approved, string fromDay, string toDay)
        {
            DateTime datetime1;
            DateTime datetime2;
            var datetime3 = DateTime.Now;
            datetime1 = DateTime.TryParse(fromDay, out datetime1) ? datetime1 : datetime3;
            datetime2 = DateTime.TryParse(toDay, out datetime2) ? datetime2 : datetime3;

            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var query = from p in dc.Articles
                        join tempArticleCat in dc.TempArticleCats
                        on p.ArticlesID equals tempArticleCat.ArticleID
                        join user in dc.aspnet_Users
                        on p.PostBy equals user.UserId
                        where p.SiteID == Configs.SiteId &&
                        (catId == 0 || (tempArticleCat.CatID == catId)) &&
                        (keyWord == string.Empty || p.Title.Contains(keyWord)) &&
                        (userId == Guid.Empty || (user.UserId == userId)) &&
                        (datetime1 == datetime3 || p.CreatedDate >= datetime1) &&
                        p.CreatedDate <= datetime2
                        orderby p.ReleaseDate descending
                        select new ArticleListView
                        {
                            ArticlesId = p.ArticlesID,
                            Title = p.Title,
                            CreatedDate = p.CreatedDate,
                            ViewCount = int.Parse(p.ViewCount.ToString()),
                            ArticlePath = p.ArticlePath,
                            ReleaseDate = p.ReleaseDate,
                            ImagePath = p.ImagePath,
                            UserName = user.UserName
                        };

            return query.ToList();
        }

        public ArticleListView ReadXmlbyId(string id, string day, string month, string year)
        {
            var sPath = Configs.ArticleFile + "ListFile\\" + year + "\\" +
                        Common.Instance.Right("0" + month, 2) + "\\" +
                        Common.Instance.Right("0" + day, 2) + "\\" + id + ".xml";
            if (!File.Exists(sPath))
            {
                return null;
            }

            var articleXml = XDocument.Load(sPath);
            var articleSource = (from x in articleXml.Descendants("Article")
                                 select new ArticleListView
                                            {
                                                // ReSharper disable PossibleNullReferenceException
                                                ArticlesId = int.Parse(x.Element("ArticlesID").Value),
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                Title = x.Element("Title").Value,
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                Body = x.Element("Body").Value,
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                ViewCount = int.Parse(x.Element("ViewCount").Value),
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                ReleaseDate = DateTime.Parse(x.Element("ReleaseDate").Value),
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                //PostVisible = int.Parse(x.Element("PostVisible").Value),
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                ArticlePath = x.Element("ArticlePath").Value,
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                ImagePath = x.Element("ImagePath").Value,
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                CategoryId = int.Parse(x.Element("CategoryId").Value),
                                                // ReSharper restore PossibleNullReferenceException
                                                // ReSharper disable PossibleNullReferenceException
                                                ArrayCatId = x.Element("ArrayCatID").Value,
                                                // ReSharper restore PossibleNullReferenceException
                                            }).SingleOrDefault();


            if (articleSource != null)
            {
                var str = articleSource.ArrayCatId.Split(new[] { '|' });

                articleSource.CategoryId = int.Parse(str[0]);
                articleSource.ChildCatId = int.Parse(str[1]);
            }

            return articleSource;
        }

        public void WriteXmlbyId(ArticleListView articleItem, string body, string arrayCatId)
        {
            var sourceFolder = Configs.ArticleFile + "ListFile\\" +
                               DateTime.Parse(articleItem.CreatedDate.ToString()).Year + "\\" +
                               Common.Instance.Right("0" + DateTime.Parse(articleItem.CreatedDate.ToString()).Month, 2) +
                               "\\" +
                               Common.Instance.Right("0" + DateTime.Parse(articleItem.CreatedDate.ToString()).Day, 2) +
                               "\\";

            if (!Directory.Exists(sourceFolder))
            {
                Directory.CreateDirectory(sourceFolder);
            }

            var strPath = sourceFolder + articleItem.ArticlesId + ".xml";

            if (File.Exists(strPath))
            {
                File.SetAttributes(strPath, FileAttributes.Normal);    
            }

            var xmlWrite = new XmlTextWriter(strPath, Encoding.UTF8);

            xmlWrite.WriteStartDocument();
            xmlWrite.WriteStartElement("Articles");
            xmlWrite.WriteStartElement("Article", null);
            xmlWrite.WriteElementString("ArticlesID", articleItem.ArticlesId.ToString());
            xmlWrite.WriteElementString("Title", articleItem.Title);
            xmlWrite.WriteElementString("Body", HttpContext.Current.Server.HtmlEncode(body));
            xmlWrite.WriteElementString("ViewCount", articleItem.ViewCount.ToString());
            xmlWrite.WriteElementString("ReleaseDate", articleItem.ReleaseDate.ToString());
            xmlWrite.WriteElementString("PostVisible", articleItem.PostVisible.ToString());
            xmlWrite.WriteElementString("ArticlePath", articleItem.ArticlePath);
            xmlWrite.WriteElementString("ImagePath", articleItem.ImagePath);
            xmlWrite.WriteElementString("Price", articleItem.Price);
            xmlWrite.WriteElementString("Currency", articleItem.Currency);
            xmlWrite.WriteElementString("CodeName", articleItem.CodeName);
            xmlWrite.WriteElementString("Quantity", articleItem.Quantity.ToString());
            xmlWrite.WriteElementString("CategoryId", articleItem.CategoryId.ToString());
            xmlWrite.WriteElementString("ArrayCatID", arrayCatId);
            xmlWrite.WriteEndElement();
            xmlWrite.WriteEndElement();
            xmlWrite.Flush();
            xmlWrite.Close();
        }

        /// <summary>
        /// Get other article
        /// </summary>
        /// <param name="releaseDate">Release Date</param>
        /// <param name="catId">Category Id</param>
        /// <param name="siteId"></param>
        /// <returns></returns>
        public List<ArticleListView> GetOtherArticle(DateTime releaseDate, int catId, int siteId)
        {
            var dc = new EmptyWallGalleryDataContext(Configs.ConnectionString);
            var query = (from p in dc.Articles
                         join cat in dc.TempArticleCats on p.ArticlesID equals cat.ArticleID
                         where p.SiteID == siteId
                         && p.ReleaseDate < releaseDate && cat.CatID == catId
                         orderby p.ReleaseDate descending
                         select new ArticleListView
                         {
                             ArticlePath = p.ArticlePath,
                             ArticlesId = p.ArticlesID,
                             ImagePath = p.ImagePath,
                             Title = p.Title,
                             Abstract = p.Abstract,
                             ReleaseDate = p.ReleaseDate
                         }).Take(10);

            return query.ToList();
        }

        //public string GenMenu()
        //{
        //    var iCount = 0;
        //    var vCount = 1;
        //    var strOut = new StringBuilder();
        //    var cat = new Categories();
        //    var article = new Articles();
        //    var catParent = cat.GetParentCat(0, 0, 2);
        //    foreach (var categoryListView in catParent.TakeWhile(categoryListView => categoryListView.CatId != 1))
        //    {
        //        if (iCount % 2 == 0)
        //        {
        //            var catSub = cat.GetParentCat(categoryListView.CatId, 0, 2);
        //            strOut.Append("<div class=\"card-page\" id=\"cardpageid-").Append(vCount).Append("\">");
        //            strOut.Append("     <div class=\"left-side\">");
        //            strOut.Append("         <div class=\"menu-card-title\">Thực đơn</div>");
        //            strOut.Append("         <h3>").Append(categoryListView.Title).Append("</h3>");
        //            foreach (var catSubItem in catSub)
        //            {
        //                strOut.Append("         <h4>").Append(catSubItem.Title).Append("</h4>");
        //                var articleList = article.GetByCat(catSubItem.CatId);
        //                foreach (var articleItem in articleList)
        //                {
        //                    strOut.Append("         <table class=\"item\">");
        //                    strOut.Append("             <tr>");
        //                    strOut.Append("                 <td class=\"image\">");
        //                    if (!string.IsNullOrEmpty(articleItem.ImagePath))
        //                    {
        //                        strOut.Append("     <a href=\"").Append(articleItem.ArticlePath).Append("\" class=\"tTip\" title=\"&lt;img src=&quot;/Uploads/admin/Product/").Append(articleItem.ArticlesID).Append("/180x0__").Append(articleItem.ImagePath).Append("&quot; alt=&quot;&quot; width=&quot;180&quot; height=&quot;180&quot; /&gt;\">" +
        //                                      "<img src=\"").Append("/Uploads/admin/Product/").Append(articleItem.ArticlesID).Append("/54x0__").Append(articleItem.ImagePath).Append("\" width=\"54\" height=\"54\" alt=\"").Append(articleItem.Title).Append("\" /></a>");
        //                    }
        //                    else
        //                    {
        //                        strOut.Append("     <a href=\"").Append(articleItem.ArticlePath).Append("\"><img src=\"/images/no_image_s.gif\" width=\"54\" height=\"54\" alt=\"").Append(articleItem.Title).Append("\" /></a>");                                
        //                    }                            
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("                 <td class=\"text\">");
        //                    strOut.Append("                     <p class=\"title\">");
        //                    strOut.Append("                         <a href=\"").Append(articleItem.ArticlePath).Append("\">").Append(articleItem.Title).Append("</a></p>");
        //                    strOut.Append("                     <p class=\"description\">").Append(articleItem.Abstract).Append("</p>");
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("                 <td class=\"menu-price\">");
        //                    if (!(string.IsNullOrEmpty(articleItem.Price) | articleItem.Price == "0"))
        //                    {
        //                        strOut.Append("                 <p>").Append(articleItem.Price).Append("</p>");
        //                    }
        //                    else
        //                    {
        //                        strOut.Append("                 <p>Call</p>");
        //                    }
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("             </tr>");
        //                    strOut.Append("         </table>");                            
        //                }
        //            }
        //            strOut.AppendLine("     </div>");
        //            vCount++;
        //        }
        //        else
        //        {
        //            var catSub = cat.GetParentCat(categoryListView.CatId, 0, 2);
        //            strOut.AppendLine("     <div class=\"right-side\">");
        //            strOut.AppendLine("         <div class=\"menu-card-link\">");
        //            //strOut.Append("             <a href=\"#\">check &amp; order your Reservation</a>");
        //            strOut.AppendLine("         </div>");
        //            strOut.AppendLine("         <h3>").Append(categoryListView.Title).Append("</h3>");
        //            foreach (var catSubItem in catSub)
        //            {
        //                strOut.Append("         <h4>").Append(catSubItem.Title).Append("</h4>");
        //                var articleList = article.GetByCat(catSubItem.CatId);
        //                foreach (var articleItem in articleList)
        //                {
        //                    strOut.Append("         <table class=\"item\">");
        //                    strOut.Append("             <tr>");
        //                    strOut.Append("                 <td class=\"image\">");
        //                    if (!string.IsNullOrEmpty(articleItem.ImagePath))
        //                    {
        //                        strOut.Append("     <a href=\"").Append(articleItem.ArticlePath).Append("\" class=\"tTip\" title=\"&lt;img src=&quot;/Uploads/admin/Product/").Append(articleItem.ArticlesID).Append("/180x0__").Append(articleItem.ImagePath).Append("&quot; alt=&quot;&quot; width=&quot;180&quot; height=&quot;180&quot; /&gt;\">" +
        //                                      "<img src=\"").Append("/Uploads/admin/Product/").Append(articleItem.ArticlesID).Append("/54x0__").Append(articleItem.ImagePath).Append("\" width=\"54\" height=\"54\" alt=\"").Append(articleItem.Title).Append("\" /></a>");
        //                    }
        //                    else
        //                    {
        //                        strOut.Append("     <a href=\"").Append(articleItem.ArticlePath).Append("\"><img src=\"/images/no_image_s.gif\" width=\"54\" height=\"54\" alt=\"").Append(articleItem.Title).Append("\" /></a>");
        //                    }
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("                 <td class=\"text\">");
        //                    strOut.Append("                     <p class=\"title\">");
        //                    strOut.Append("                         <a href=\"#\">").Append(articleItem.Title).Append("</a></p>");
        //                    strOut.Append("                     <p class=\"description\">").Append(articleItem.Abstract).Append("</p>");
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("                 <td class=\"menu-price\">");
        //                    if (!(string.IsNullOrEmpty(articleItem.Price) | articleItem.Price == "0"))
        //                    {
        //                        strOut.Append("                 <p>").Append(articleItem.Price).Append("</p>");
        //                    }
        //                    else
        //                    {
        //                        strOut.Append("                 <p>Call</p>");
        //                    }
        //                    strOut.Append("                 </td>");
        //                    strOut.Append("             </tr>");
        //                    strOut.Append("         </table>");
        //                }
        //            }
        //            //strOut.Append("         <table class=\"item\">");
        //            //strOut.Append("             <tr>");
        //            //strOut.Append("                 <td class=\"image\">");
        //            //strOut.Append("                     <a href=\"#\" class=\"tTip\" title=\"&lt;img src=&quot;/template/bordeaux/images/image-94.jpg&quot; alt=&quot;&quot; width=&quot;180&quot; height=&quot;180&quot; /&gt;\">");
        //            //strOut.Append("                         <img src=\"/template/bordeaux/images/image-93.jpg\" alt=\"\" width=\"54\" height=\"54\" /></a>");
        //            //strOut.Append("                 </td>");
        //            //strOut.Append("                 <td class=\"text\">");
        //            //strOut.Append("                     <p class=\"title\">");
        //            //strOut.Append("                         <a href=\"#\">Silver Oak Trophy Red</a></p>");
        //            //strOut.Append("                     <p class=\"description\">Luxurious, well-rounded flavors that define Silver Oak Cabernet Sauvignon</p>");
        //            //strOut.Append("                 </td>");
        //            //strOut.Append("                 <td class=\"menu-price\">");
        //            //strOut.Append("                     <p>$29,99</p>");
        //            //strOut.Append("                 </td>");
        //            //strOut.Append("             </tr>");
        //            //strOut.Append("         </table>");
        //            strOut.AppendLine("     </div>");
        //            strOut.AppendLine("     <div class=\"clear\"></div>");
        //            strOut.AppendLine("</div>");  
        //        }
        //        iCount++;
        //    }
        //    return strOut.ToString();
        //}
    }
}